﻿using System;
using System.Collections.Generic;
using System.Data.Objects;
using System.Linq;
using System.Text;

namespace Engine.DAL.Repositories
{
    public abstract class RepositoryManagerBase
    {
        private readonly ObjectContext _objectContext;

        private readonly Dictionary<Type, Type> _dependenceMap = new Dictionary<Type, Type>();

        protected RepositoryManagerBase(ObjectContext objectContext)
        {
            _objectContext = objectContext;
        }

        public T Get<T>()
        {
            return (T)Activator.CreateInstance(_dependenceMap[typeof(T)], _objectContext);
        }

        public void SubmitChanges()
        {
            _objectContext.SaveChanges();
        }

        public void Dispose()
        {
            _objectContext.Dispose();
        }

        protected void Bind(Type interfaceType, Type instanceType)
        {
            _dependenceMap.Add(interfaceType, instanceType);
        }
    }
}
